package com.yuhang.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuhang.entity.HyAdmin;
import com.yuhang.entity.HyPayProject;
import com.yuhang.service.HyPayProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhang
 * @since 2021-03-11
 */
@RestController
@RequestMapping("/hy-pay-project")
public class HyPayProjectController {

    @Autowired
    private HyPayProjectService hyPayProjectService;

    @RequestMapping("/showAllPayProject")
    public Map<String,Object> showAllPayProject(@RequestParam(value = "page",defaultValue = "1")int pageNum,
                                          @RequestParam(value = "limit",defaultValue = "5")int pageSize){
        IPage<HyPayProject> page = hyPayProjectService.selectByPage(pageNum, pageSize);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("count",page.getTotal());
        map.put("data",page.getRecords());
        map.put("msg","");
        return map;
    }

    @RequestMapping("/showAll")
    public Map<String,Object> showAll(){
        List<HyPayProject> list = hyPayProjectService.list();
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("data",list);
        map.put("msg","");
        return map;
    }


    @RequestMapping("/addPayProject")
    public Map<String,Object> addPayProject(HyPayProject hyPayProject){
        hyPayProject.setState(1);
        hyPayProjectService.save(hyPayProject);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/updatePayProject")
    public Map<String,Object> updatePayProject(HyPayProject hyPayProject){
        hyPayProjectService.updateById(hyPayProject);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

    @RequestMapping("/deletePayProject")
    public Map<String,Object> deletePayProject(Integer id){
        HyPayProject hyPayProject = hyPayProjectService.getById(id);
        if(hyPayProject.getState()==1){
            hyPayProject.setState(0);
        }
        hyPayProjectService.save(hyPayProject);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        return map;
    }

}
